package cn.neusoft.service.impl;

import cn.neusoft.domain.CargoExImportBill;
import cn.neusoft.mapper.ExImportBillMapper;
import cn.neusoft.service.ExImportBillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
public class ExImportBillImp implements ExImportBillService {
    @Autowired
    private ExImportBillMapper exImportBillMapper;
    @Override
    public List<CargoExImportBill> ExImportBillQueryAll(String warehouseName, Date from, Date to) {
        List<CargoExImportBill> list = new ArrayList<CargoExImportBill>();

        if(warehouseName != null){
            List<CargoExImportBill> temp = exImportBillMapper.getAll();
            for(CargoExImportBill bill : temp){
                if(!warehouseName.equals("") && !bill.getWarehouseName().equals(warehouseName)){
                    continue;
                }
                if(from == null){
                    if(to == null){
                        list.add(bill);
                    }
                    else{
                        if(bill.getDate().compareTo(to) <= 0){
                            list.add(bill);
                        }
                    }
                }
                else{
                    if(to == null){
                        if(bill.getDate().compareTo(from) >= 0){
                            list.add(bill);
                        }
                    }
                    else{
                        if(bill.getDate().compareTo(from) >= 0 && bill.getDate().compareTo(to) <= 0){
                            list.add(bill);
                        }
                    }
                }

            }
        }

        return list;
    }



}
